/**
 * Created by IntelliJ IDEA.
 * User: Bezdelnick
 * Date: 9/25/12
 * Time: 8:51 PM
 * To change this template use File | Settings | File Templates.
 */
package vplib.model {

import mx.collections.ArrayCollection;

public class AbstractPhysicsModel {
    protected var _properties:ArrayCollection;

    public function AbstractPhysicsModel() {
        this._properties = new ArrayCollection();
    }

    public function get properties():ArrayCollection {
        return _properties;
    }

    public function getPropertyByName(name:String):PhysicsProperty {
        for each (var prop:PhysicsProperty in this._properties) {
            if (prop.name == name)
                return prop;
        }
        return null;
    }

    public function addProperty(prop:PhysicsProperty):void {
        _properties.addItem(prop);
    }

    public function editProperty(prop:PhysicsProperty):void {
        var position:int = -1;
        for each (var p:PhysicsProperty in this._properties) {
            if (p.name == prop.name)
                position = this._properties.getItemIndex(p);
        }

        if (position != -1)
            _properties.removeItemAt(position);

        _properties.addItem(prop);
    }

    public function removeProperty(name:String):void {
        var position:int = -1;
        for each (var p:PhysicsProperty in this._properties) {
            if (p.name == name)
                position = this._properties.getItemIndex(p);
        }

        if (position != -1)
            _properties.removeItemAt(position);
    }


    public function toString():String {
        var result:String;
        result = "[AbstractPhysicsModel] \t- toString(); - properties: { length: " + _properties.length + "; };";
        return result;
    }
}
}